using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using RetailAnalytic.Core;

namespace RetailAnalytic.Tools.ActivitySystem
{
    public partial class ucUserHistory : UserControl
    {
        public ucUserHistory()
        {

            InitializeComponent();
            SetGuiAppearance();
            InitHist();
        }
        private void SetGuiAppearance()
        {
            this.ultraToolbarsManager1.Tools["bt_print"].SharedProps.AppearancesSmall.Appearance.Image = SR.ImagesLibrary.GetImageByName("print");// ("Pre_print");
        }

        public void InitHist()
        {
            DataTable _dtHist = new DataTable("UserHist");
            /*
              _sqlcm.Parameters.Add("@UsrLog_uid", SqlDbType.Int).Value = this.user.userID ;
            _sqlcm.Parameters.Add("@UsrLog_datetime", SqlDbType.DateTime).Value = System.DateTime.Now;
            _sqlcm.Parameters.Add("@UsrLog_session", SqlDbType.NVarChar).Value = idSession ;
            _sqlcm.Parameters.Add("@UsrLog_EventType", SqlDbType.NVarChar ).Value = sEvent;
            _sqlcm.Parameters.Add("@UsrLog_ClassTaskID", SqlDbType.Int).Value = classTaskID;
            _sqlcm.Parameters.Add("@UsrLog_Status", SqlDbType.Int).Value = 0;
            _sqlcm.Parameters.Add("@UsrLog_extended", SqlDbType.VarChar).Value = sExtend;
            _sqlcm.Parameters.Add("@UsrLog_Host", SqlDbType.VarChar).Value = System.Net.Dns.GetHostName();
            _sqlcm.Parameters.Add("@UsrLog_version", SqlDbType.VarChar).Value = Application.ProductVersion; 
              */
            string selectAnyTableOrder = "SELECT * FROM {0} ORDER BY {1} DESC";
            string _stext = string.Format(selectAnyTableOrder, "RA.UsrLog", "UsrLog_datetime");
            SqlDataAdapter _sda = new SqlDataAdapter(_stext, SessionConfiguration.Dbconnection);
            //DataTable table = new DataTable("ClassTask");
            _sda.Fill(_dtHist);
            ugUserHist.DataSource = _dtHist;
            foreach (DataColumn col in ((DataTable)ugUserHist.DataSource).Columns)
            {
                col.ReadOnly = true;
            }
        }

        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "bt_print":    // ButtonTool
                    // Place code here
                    //ultraGridPrintDocument1.Print();
                    ultraPrintPreviewDialog1.Show();
                    break;

            }

        }
    }
}
